package be.jabapage.gui;

import java.awt.Dimension;
import java.awt.Rectangle;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import org.apache.log4j.Logger;

import be.jabapage.util.PropertiesSingleton;

public abstract class SnookerAppInternalFrame extends JInternalFrame {

	protected JFrame frame;
	protected JDesktopPane desk;
	protected PropertiesSingleton properties = PropertiesSingleton.getInstance();
	protected Logger logger = Logger.getRootLogger();
	protected boolean isPack;
	public SnookerAppInternalFrame(JFrame frame) {
		super();
		this.frame = frame;
		this.desk = (JDesktopPane) frame.getContentPane();
		properties = PropertiesSingleton.getInstance();
	}

	public void afterConstruct() {
		this.setIconifiable(true);
		this.setMaximizable(true);
		this.setResizable(true);
		this.setClosable(true);
		this.isPack = false;
		this.doPainting();
		this.reSize();
	}
	public void reSize() {
		this.setTitle(getString("title"));
		int width = Integer.parseInt(getGUIProperty("width"));
		int height = Integer.parseInt(getGUIProperty("height"));
		Rectangle bounds = new Rectangle(new Dimension(width,height));
		setBounds(bounds);
		setMaximumSize(new Dimension(width,height));
		this.setVisible(true);
		if (isPack)
			this.pack();
	}
	
	public String getString (String key) {
		String result = "";
		try {
			String className = this.getClass().getName().toLowerCase();
			logger.debug("className = " + className);
			result = properties.getString("app." + className + "." + key);
		} catch (RuntimeException e) {
			logger.debug("specific settings not found, use default one");
			result = properties.getString("app.default." + key);
		}
		if (result == null) {
			logger.debug("specific settings not found, use default one");
			result = properties.getString("app.default." + key);
		}
		return result;
	}
	
	public String getGUIProperty(String key) {
		String result = "";
		try {
			String className = this.getClass().getName().toLowerCase();
			result = properties.getGUIProperty(className +"." + key);
		} catch (RuntimeException e) {
			logger.debug("specific settings not found, use default one");
			result = properties.getGUIProperty("default." + key);
		}
		if (result == null) {
			logger.debug("specific settings not found, use default one");
			result = properties.getGUIProperty("default." + key);
		}
		return result;
	}
	

	public abstract void doPainting() ;
	

}
